#include<iostream>
#include<vector>
#include<algorithm>
#include<mpi.h>

using namespace std;
int 
main(int argc, char * argv[])
{
  int rank, proc_count;
  MPI_File fh;
  MPI_Status status;
  vector<double> vec_buf(2);

  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &proc_count);
  MPI_File_open(MPI_COMM_WORLD, "tmp.dat",
	  	MPI_MODE_RDONLY, MPI_INFO_NULL,
		&fh);

  for( int i = 0; i < 2; i ++ )
  {
	MPI_Barrier(MPI_COMM_WORLD);
	if( rank == 1 - i )
	{
	  MPI_File_read_shared(fh, &vec_buf[0], 1, 
		  MPI_DOUBLE, &status);
	  MPI_File_read_shared(fh, &vec_buf[1], 1, 
		  MPI_DOUBLE, &status);
	}
  }
  MPI_File_close(&fh);
  cout << "Rank " << rank << endl;
  cout << vec_buf[0] << vec_buf[1] << endl;
  MPI_Finalize();
  return 0;
}
